package com.wutao.panzh.admin.content.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.panzh.UtilEntity.ResultVO;
import com.panzh.entity.InformationItem;
import com.panzh.entity.RouteImag;
import com.panzh.myconst.CommonConst;
import com.wutao.panzh.service.RouteImagService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class RouteImagController {

    @Reference
    private RouteImagService routeImagService;

    //    get/all/route/imag routeId
    @RequestMapping("/get/all/route/imag")
    @ResponseBody
    public ResultVO getAllRouteImagByRouteId(@RequestParam("routeId") String routeId){
        List<RouteImag> routeImags = routeImagService.getAllRouteImagByRouteId(routeId);
        if (routeImags.size() == 0 || routeImags == null){
            return new ResultVO<String>(ResultVO.FAILED, CommonConst.INFORMATION_DOES_NOT_EXIST,ResultVO.NO_DATA);
        }
        return new ResultVO<List<RouteImag>>(ResultVO.SUCCESS, ResultVO.NO_MSG,routeImags);
    }



    //    remove/route/imag  "imagSrc":imagSrc, "routeId":routeId
    @RequestMapping("/remove/route/imag")
    @ResponseBody
    public ResultVO removeRouteimag(@RequestParam("routeId") String routeId,
                                    @RequestParam("imagSrc") String imagSrc){
        try {
            routeImagService.removeImagByRouteIdAndImagSrc(imagSrc,routeId);
        } catch (Exception e) {
            return new ResultVO<String>(ResultVO.FAILED, CommonConst.DELETE_INFORMATION_EXCEPTION,ResultVO.NO_DATA);
        }
        return new ResultVO<String>(ResultVO.SUCCESS, CommonConst.DELETE_INFORMATION_SUCCESS,ResultVO.NO_DATA);
    }

}
